/**
 * @name        buildRollupConfig.ts
 * @author      shenyc
 * @date        2020-05-06 - ?
 * @copyright   Copy right (c) shenyc (shenyczz@163.com).
 *              All rights reserved.
 *
 ******************************************************************************/
// {{@@@}}
"use strict";
// ----------------------------------------------------------------------------
import type {
    //
    InputOption,
    InputPluginOption,
    OutputOptions,
    OutputPluginOption,
    RollupOptions,
    GlobalsOption,
} from "rollup";

import { getPreferenceOption } from "./PreferenceOption";
// ----------------------------------------------------------------------------
/**
 * 构造 rollup 配置
 * @param inputs    - 输入选项 {@link InputOption}
 * @param outputs   - 输出选项数组 {@link OutputOptions}[]
 * @param plugins   - 插件选项 {@link InputPluginOption}
 * @returns
 */
function buildRollupConfig(inputs: InputOption, outputs: OutputOptions[], plugins?: InputPluginOption) {
    //
    const _options = getPreferenceOption();
    const _externals = _options.externals;
    const _plugins = plugins ?? _options.plugins;
    const _result: RollupOptions = {
        input: inputs,
        output: outputs,
        plugins: _plugins,
        treeshake: true,
        external: _externals,
        // 用来指定代码执行环境的参数，解决this执行undefined问题
        context: "window",
    };

    return _result;
}

export { buildRollupConfig };
// ----------------------------------------------------------------------------
// {{@@@}}

/*
export interface RollupOptions extends InputOptions {
    // This is included for compatibility with config files but ignored by rollup.rollup
    output?: OutputOptions | OutputOptions[];
}

export interface InputOptions {
    cache?: boolean | RollupCache;
    context?: string;
    experimentalCacheExpiry?: number;
    experimentalLogSideEffects?: boolean;
    external?: ExternalOption;
    input?: InputOption;
    jsx?: false | JsxPreset | JsxOptions;
    logLevel?: LogLevelOption;
    makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource';
    maxParallelFileOps?: number;
    moduleContext?: ((id: string) => string | NullValue) | Record<string, string>;
    onLog?: LogHandlerWithDefault;
    onwarn?: WarningHandlerWithDefault;
    perf?: boolean;
    plugins?: InputPluginOption;
    preserveEntrySignatures?: PreserveEntrySignaturesOption;
    preserveSymlinks?: boolean;
    shimMissingExports?: boolean;
    strictDeprecations?: boolean;
    treeshake?: boolean | TreeshakingPreset | TreeshakingOptions;
    watch?: WatcherOptions | false;
}

export interface OutputOptions {
    amd?: AmdOptions;
    assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string);
    banner?: string | AddonFunction;
    chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
    compact?: boolean;
    // only required for bundle.write
    dir?: string;
    dynamicImportInCjs?: boolean;
    entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
    esModule?: boolean | 'if-default-prop';
    experimentalMinChunkSize?: number;
    exports?: 'default' | 'named' | 'none' | 'auto';
    extend?: boolean;
    // /** @deprecated Use "externalImportAttributes" instead.
    externalImportAssertions?: boolean;
    externalImportAttributes?: boolean;
    externalLiveBindings?: boolean;
    // only required for bundle.write
    file?: string;
    footer?: string | AddonFunction;
    format?: ModuleFormat;
    freeze?: boolean;
    generatedCode?: GeneratedCodePreset | GeneratedCodeOptions;
    globals?: GlobalsOption;
    hashCharacters?: HashCharacters;
    hoistTransitiveImports?: boolean;
    importAttributesKey?: ImportAttributesKey;
    indent?: string | boolean;
    inlineDynamicImports?: boolean;
    interop?: InteropType | GetInterop;
    intro?: string | AddonFunction;
    manualChunks?: ManualChunksOption;
    minifyInternalExports?: boolean;
    name?: string;
    noConflict?: boolean;
    outro?: string | AddonFunction;
    paths?: OptionsPaths;
    plugins?: OutputPluginOption;
    preserveModules?: boolean;
    preserveModulesRoot?: string;
    reexportProtoFromExternal?: boolean;
    sanitizeFileName?: boolean | ((fileName: string) => string);
    sourcemap?: boolean | 'inline' | 'hidden';
    sourcemapBaseUrl?: string;
    sourcemapExcludeSources?: boolean;
    sourcemapFile?: string;
    sourcemapFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
    sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption;
    sourcemapPathTransform?: SourcemapPathTransformOption;
    sourcemapDebugIds?: boolean;
    strict?: boolean;
    systemNullSetters?: boolean;
    validate?: boolean;
    virtualDirname?: string;
}

*/
